#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int n,q;
int go[N][22][2];
vector<int>edge[N];
int nums[N];
int d[N];
void dfs(int u,int v){
	d[u] = d[v] + 1;
	go[u][0][0] = v;
	go[u][0][1] = nums[v];
	for(int i : edge[u]){
		if(i == v)continue;
		dfs(i,u);
	} 
}
void init(){
	for(int i = 1;i<log(n);i++){
		for(int j = 1;j<=n;j++){
			go[j][i][0] = go[go[j][i-1][0]][i-1][0];
			go[j][i][1] = go[go[j][i-1][0]][i-1][1] | go[j][i-1][1];
		}
	}
}
int lca(int x,int y){
	int ans = nums[x] | nums[y];
	if(d[x]>d[y])swap(x,y);
	for(int i = log(n);i>=0;i--){
		if((1<<i) <= d[y] - d[x]){
			ans |= go[y][i][1];
			y = go[y][i][0];
		}	
	}

	if(x==y)return ans;

	for(int i = log(n);i>=0;i--){
		if(go[x][i][0] != go[y][i][0]){
			ans |= go[x][i][1] | go[y][i][1];
			x = go[x][i][0];
			y = go[y][i][0];
		}	
	}
	ans |= go[x][0][1];
	
	return ans;
}
int f(int a){
	int cnt = 0;
	while(a){
		a -= (a&-a);
		cnt++;
	}
	return cnt;
}
int main(){
	int t1,t2;
	cin>>n>>q;
	for(int i = 1;i<=n;i++){
		int t;
		cin>>t;
		nums[i] = 1<<(t-1);
	}
	for(int i = 1;i<n;i++){
		cin>>t1>>t2;
		edge[t1].push_back(t2);
		edge[t2].push_back(t1);
	}
	dfs(1,0);
	init();
	for(int i = 0;i<q;i++){
		cin>>t1>>t2;
		cout<<f(lca(t1,t2))<<endl;
	}
	return 0;
} 
